<?php
	$ERR='1.52 - Please update -> ';
	$OLD_SUM='616c0b3e243e98a64713a8fa65fd873d'; //1.41
	//$CURR_SUM='d4858e90fe1333017e84ae3613ddcb59'; 1.51
	$CURR_SUM='170e400e79dc8fa4fffd82fff46f2334';
	$SUM_DEBUG='526d36c70849bbe91c6ae0626fc2470b';
	

	if($_GET['getLatestVersion']=='true') {
		if($_GET['md5sum']==$CURR_SUM || $_GET['md5sum']==$OLD_SUM || $_GET['test']=='12345') {
			echo 'ok';
		}
		else {
			echo 'needupdate';
		}
	}
	
	else {
		if($_GET['md5sum']==$OLD_SUM || $_GET['md5sum']==$CURR_SUM || $_GET['md5sum']==$SUM_DEBUG ||  $_GET['action']=='arrive' || $_GET['action']=='startFlight') {
			extract($_GET);
			
			$url = 'http://atilla.hinttech.com/fseconomy/fsagentFSX';
			$fields = $_GET;
			$_GET['md5sum']="";
			
			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
			rtrim($fields_string,'&');
			
			$ch = curl_init();
			
			curl_setopt($ch,CURLOPT_URL,$url);
			curl_setopt($ch,CURLOPT_POST,count($fields));
			curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
			
			$result = curl_exec($ch);
			
			curl_close($ch);
			
			/*$myFile = "error.txt";
			$fh = fopen($myFile, 'a');
			$stringData = date('l jS \of F Y h:i:s A').' -- '.$_GET['user'].' -- '.$_GET['action'].' -- '.$_GET['aircraft']."\n";
			fwrite($fh, $stringData);
			fclose($fh);*/


		} else {
			echo '<?xml version="1.0"?><response><notok>'.$ERR.'</notok></response>';
			
			/*function myfunction($v1,$v2) 
			{
				return $v1 . "-" . $v2;
			}
			
			$myFile = "error.txt";
			$fh = fopen($myFile, 'a');
			$stringData = array_reduce($_GET,"myfunction",5)."\n";
			fwrite($fh, $stringData);
			fclose($fh);*/
		}
	}
	
?>